package org.jash.learnmvp.video;

import org.jash.learnmvp.mvp.BasePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

public class VideoPresenter extends BasePresenter<ConStruct.IVideoView> implements ConStruct.IVideoPresenter {
    private ConStruct.IVideoModel model = new VideoModel();
    @Override
    public void loadAllVideo() {
        disposable.add(model.getAllVideo()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(res -> {
                    if (isAttach()) {
                        if (res.getCode() == 0) {
                            getWhoView().videoSuccess(res.getData());
                        } else {
                            getWhoView().videoFailure(new RuntimeException(res.getMsg()));
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().videoFailure(t);
                    }
                }));
    }
}
